package com.warm.base.algorithm.structure;

import java.util.HashMap;
import java.util.TreeMap;

/**
 * @Description TODO
 * @Author iyb-liangchuang
 * @Date 2021/4/9 10:09
 */
public class Client {

    public static void main(String[] args) {
        TreeMap treeMap = new TreeMap();
        treeMap.put(new Key(), "value one");
        treeMap.put(new Key(), "value two");
        // treeMap 的 key 去重是根据排序结果
        System.out.println(treeMap.size());

        HashMap hashMap = new HashMap();
        hashMap.put(new Key(), "value one");
        hashMap.put(new Key(), "value two");
        // hashMap 使用 hashCode 和 equals 实现去重
        System.out.println(hashMap.size());
    }

    static class Key implements Comparable<Key>{
        @Override
        public int compareTo(Key o) {
            return -1;
        }

        @Override
        public int hashCode() {
            return 1;
        }

        @Override
        public boolean equals(Object obj) {
            return true;
        }
    }
}
